package com.firefly.service.command.cms;

import com.firefly.dao.dao.cms.po.TypePo;
import com.firefly.dao.dao.cms.service.TypeService;
import com.firefly.util.handle.FireflyException;
import com.firefly.dao.assembler.cms.TypeAssembler;
import com.firefly.dao.dto.cms.TypeDto;
import com.firefly.dao.dto.cms.TypeSortDto;
import com.firefly.service.repository.cms.TypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 分类
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/13
 **/
@Service
public class TypeCommand {
    private final TypeService typesService;
    private final TypeAssembler typeAssembler;
    private final TypeRepository typeRepository;
    @Autowired
    public TypeCommand(TypeRepository typeRepository, TypeAssembler typeAssembler, TypeService typesService){
        this.typeRepository = typeRepository;
        this.typeAssembler = typeAssembler;
        this.typesService = typesService;
    }

    public Boolean create(TypeDto request){
        TypePo entity = typeAssembler.getPo(request);
        return typeRepository.create(entity);
    }
    public Boolean updateName(TypeDto request){
        if (request.getId() == request.getParentId()){
			throw new FireflyException(403,"父栏目不能选择自己");
		}
        TypePo entity = typeAssembler.getPo(request);
        return typeRepository.updateName(entity);
    }
    public Boolean sort(TypeSortDto request) {
        return typeRepository.sort(request.getId(),request.getSort());
    }

    //	删除单条
    public Boolean remove(int id) {
        List<Integer> ids = typeRepository.getIds(id);
        return typeRepository.removeId(ids);
    }
}
